﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace Loki
{
    /// <summary>
    /// A small helper class that has a method to help create
    /// PropertyChangedEventArgs when using the INotifyPropertyChanged
    /// interface.
    /// </summary>
    public static class ObservableHelper
    {
        #region Public Methods
        /// <summary>
        /// Creates PropertyChangedEventArgs.
        /// </summary>
        /// <param name="propertyExpression">Expression to make 
        /// PropertyChangedEventArgs out of</param>
        /// <returns>PropertyChangedEventArgs</returns>
        public static PropertyChangedEventArgs CreateArgs<T>(
            Expression<Func<T, Object>> propertyExpression)
        {
            return new PropertyChangedEventArgs(
                 ExpressionHelper.Reflect<T>.GetProperty(propertyExpression).Name);
        }

        public static PropertyChangingEventArgs CreateChangingArgs<T>(
            Expression<Func<T, object>> propertyExpression)
        {
            return new PropertyChangingEventArgs(
                 ExpressionHelper.Reflect<T>.GetProperty(propertyExpression).Name);
        }
        #endregion
    }
}
